package com.liqi.frame.comm.service.impl;

import com.liqi.frame.comm.dao.PermissionDao;
import com.liqi.frame.comm.po.Permission;
import com.liqi.frame.comm.service.PermissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * Created by liqi on 2017/8/2.
 */
@Service("permissionService")
public class PermissionServiceImpl implements PermissionService {
    public Set<String> findPermissionByUserId(String userId) {
        return permissionDao.findPermissionByUserId(userId);
    }

    @Override
    public int insertPermission(String id, String permissionKey, String permissionName, String permissionType, String parentId, Integer level, String comment, Float orderId, String target, String href) {
        return permissionDao.insertObject(id, permissionKey, permissionName, permissionType, parentId, level, comment, orderId, target, href);
    }

    @Override
    public int updatePermission(String id, String permissionKey, String permissionName, String permissionType, String parentId, Integer level, String comment, Float orderId, String target, String href) {
        return permissionDao.updateObject(id, permissionKey, permissionName, permissionType, parentId, level, comment, orderId, target, href);
    }

    @Override
    public int deletePermissionById(String id) {
        return permissionDao.deletePermissionById(id);
    }

    @Override
    public List<Permission> getPermissionListByRoleId(String roleId) {
        return permissionDao.getPermissionListByRoleId(roleId);
    }

    @Override
    public List<Permission> getPermissionListByUserId(String userId) {

        return permissionDao.getPermissionListByUserId(userId);
    }

    @Override
    public int deletePermissionsByIds(String[] ids) {
        return 0;
    }

    @Override
    public int deleteMenuListByParentId(String parentId) {
        if (parentId==null || Objects.equals("",parentId)) {
            return 0;
        }
        return permissionDao.deleteMenuListByParentId(parentId);
    }

    @Resource
    private PermissionDao permissionDao;
}
